package cn.lanqiao.common.identifyingCode;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

public class ImageUtils
{
  public static void outputHeightImage(int w, int h, OutputStream os, String code)
    throws IOException
  {
    BufferedImage image = HeightCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
  }
  
  public static BufferedImage getHeightImage(int w, int h, String code)
    throws IOException
  {
    BufferedImage image = HeightCode.getBufferedImage(h, w, code);
    return image;
  }
  
  public static String outputHeightImage(int w, int h, OutputStream os, Integer count)
    throws IOException
  {
    String code = HeightCode.generateVerifyCode(count.intValue());
    BufferedImage image = HeightCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
    return code;
  }
  
  public static String outputHeightImage(int w, int h, OutputStream os, Integer count, String sources)
    throws IOException
  {
    String code = HeightCode.generateVerifyCode(count.intValue(), sources);
    BufferedImage image = HeightCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
    return code;
  }
  
  public static void outputLowImage(int w, int h, OutputStream os, String code)
    throws IOException
  {
    BufferedImage image = LowCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
  }
  
  public static String outputLowImage(int w, int h, OutputStream os, Integer count)
    throws IOException
  {
    String code = LowCode.generateVerifyCode(count.intValue());
    BufferedImage image = LowCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
    return code;
  }
  
  public static String outputLowImage(int w, int h, OutputStream os, Integer count, String sources)
    throws IOException
  {
    String code = LowCode.generateVerifyCode(count.intValue(), sources);
    BufferedImage image = LowCode.getBufferedImage(h, w, code);
    ImageIO.write(image, "jpg", os);
    return code;
  }
}
